<project name="JSARP" default="dist" basedir=".">

	<property name="source"				location="source"			/>
	<property name="classes"			location="classes"		/>
	<property name="src.lib"			location="lib"				/>
	<property name="src.resource" location="resources"	/>
	<property name="bin"  				location="bin"				/>
	<property name="doc"  				location="doc"				/>
	<property name="lib"  				location="bin/lib"		/>
	<property name="resource"  		location="bin/resources" />
	<property name="jarname"			location="bin/jsarp.jar"	/>
	
	<path id="compile.classpath">
		<fileset dir="${src.lib}">
			<include name="**/forms-1.0.7.jar"/>
			<include name="**/xpp3_min-1.1.3.4.O.jar"/>
			<include name="**/xstream-1.2.1.jar"/>
		</fileset>
	</path>
	
	<target name="clean" description="Apaga as pastas destino da compilacao" >
		<echo>Apagando as pastas destino da compilacao</echo>
		<echo>Removing the folders destination of the compilation</echo>
		<delete dir="${bin}"		/>
		<delete dir="${classes}"/>
		<delete dir="${doc}"/>
		<delete file="jsarp_doc.zip"/>
		<delete file="jsarp_bin.zip"/>
		<delete file="jsarp_src.zip"/>
		<delete file="Version.txt"/>
	</target>
  
	<target name="compile" description="compila os fontes " >
		<echo>Compilando os fontes</echo>
		<echo>Compiling the sources</echo>
		<mkdir dir="${classes}"/>
		<javac srcdir="${source}" destdir="${classes}" classpathref="compile.classpath"/>
	</target>
	
	<target name="generatedoc" description="Gera o Javadoc dos fontes" >
		<echo>Gerando Javadoc</echo>
		<echo>Generating Javadoc</echo>
		<mkdir dir="${doc}"/>
		<javadoc
				  packagenames="br.*"
				  sourcepath="${source}"
				  destdir="${doc}"
				  author="true"
				  version="true"
				  use="true"
				  private="true"
				  windowtitle="JSARP - Simulador/Analisador de Redes de Petri"
				  classpathref="compile.classpath">
		</javadoc>
	</target>
	
	<target name="generatescript" description="Gera os scripts de start para Windows e Linux">
		<echo>Criando scripts de execucao do programa</echo>
		<echo>Creating scripts of execution of the program</echo>
		<mkdir dir="${bin}"/>
		<delete file="${bin}/start.sh" />
		<delete file="${bin}/start.bat"/>
		<concat destfile="${bin}/start.sh" >java -jar jsarp.jar</concat>
		<concat destfile="${bin}/start.bat">java -jar jsarp.jar</concat>
		<chmod file="${bin}/start.sh" perm="ug+rx"/>
	</target>

	<target name="createjar" depends="compile" description="Cria o arquivo jar" >
		<echo>Criando arquivo jsarp.jar</echo>
		<echo>Creating jsarp.jar file</echo>
		<mkdir dir="${bin}"/>
		<jar destfile="${jarname}" basedir="${classes}">
			<manifest>
				<attribute name="Built-By" value="Felipe Lino"/>
				<attribute name="Main-Class" value="br.uerj.petrinetanalyzer.gui.MainProgram"/>
				<attribute name="Class-Path" value="lib/forms-1.0.7.jar lib/xpp3_min-1.1.3.4.O.jar lib/xstream-1.2.1.jar" />
				<section name="br/uerj/petrinetanalyzer/gui/MainProgram.class">
					<attribute name="Java-Bean" value="True"/>
				</section>
			</manifest>
		</jar>
	</target>
	
	<target name="copyfiles" description="Copia as pastas resource e lib para a pasta bin">
		<echo>Copiando arquivos necessarios para execucao</echo>
		<echo>Copying necessary files for execution</echo>
		<mkdir dir="${resource}"/>
		<mkdir dir="${lib}"		/>
		<copy todir="${resource}">
			<fileset dir="${src.resource}" includes="**/*.properties"/>
		</copy>
		<copy todir="${lib}">
			<fileset dir="${src.lib}" includes="**/*.jar"/>
		</copy>
		<copy todir="${bin}">
			<fileset dir="./" includes="**/*.txt"/>
		</copy>
	</target>
	
	<target name="versionfile" description="Cria o arquivo com o time stamp da geracao do ant">
		<echo>Criando arquivo Version.txt</echo>
		<echo>Creating Version.txt file</echo>
		<tstamp>
      <format property="touch.time" pattern="dd/MM/yyyy hh:mm aa"/>
	  </tstamp>
		<concat destfile="Version.txt">JSARP - Simulador/Analisador de Redes de Petri em Java
Author: Felipe G. de Oliveira Lino - IME/UERJ
Create: ${touch.time}
E-mail: felipelino44@gmail.com
	</concat>
	</target>
	
	<target name="zipsource" description="Cria um arquivo zip apenas com os fontes do programa">
		<echo>Criando jsarp_src.zip com os fontes do programa</echo>
		<echo>Creating jsarp_src.zip with sources of the program</echo>
		<zip destfile="jsarp_src.zip">
			<fileset dir="./" excludes="**/*.bak"/>
		</zip>
	</target>
	
	<target name="zipfiles" description="Cria 2 arquivos zip um com o binario do programa outro com o javadoc">
		<echo>Criando jsarp_doc.zip com a documentacao das classes</echo>
		<echo>Creating jsarp_doc.zip with documentation of the sources</echo>
		<delete file="jsarp_doc.zip"/>
		<zip destfile="jsarp_doc.zip">
			<fileset dir="${doc}"/>
		</zip>
		<echo></echo>
		<echo>Criando jsarp_bin.zip com o programa</echo>
		<echo>Creating jsarp_bin.zip with the program</echo> 
		<delete file="jsarp_bin.zip"/>
		
		<zip destfile="jsarp_bin.zip">
			<fileset dir="${bin}"/>
		</zip>
	</target>
	
	<target name="message" description="Exibe mensagem">
		<echo>Criando distribuicao</echo>
		<echo>Creating distribution</echo>
	</target>
	
	<target name="dist" depends="message, clean, versionfile, zipsource, compile, createjar, generatescript, copyfiles, generatedoc, zipfiles" description="Gera distribuicao">
		<echo>Distribuicao criada</echo>
		<echo>Distribution create</echo>
	</target>
	
</project>